using NUnit.Framework;
using ValidationFramework.Specifications;
using ValidationFramework.Specifications.Tests.Helpers;

namespace ValidationFramework.Specifications.Tests
{
	public class SatisfiesDelegateAttributeTests
	{
		// Attribute is nolonger responsible for this
		//[TestFixture]
		//public class Construction
		//{
		//    [Test]
		//    [ExpectedException(typeof(ArgumentException))]
		//    public void Should_Throw_Exception_When_Given_Invalid_Type()
		//    {
		//        // Arrange
		//        var typeName = "InvalidType";
		//        var methodName = "ValidateValid";
		//        new DelegateSpecAttribute(typeName, methodName, "This should always fail");
		//    }

		//    [Test]
		//    [ExpectedException(typeof(ArgumentException))]
		//    public void Should_Throw_Exception_When_Given_Invalid_Method()
		//    {
		//        // Arrange
		//        var typeName = typeof(DelegateSpecTest.ValidationClass).FullName;
		//        var methodName = "NonExistantMethod";
		//        new DelegateSpecAttribute(typeName, methodName, "This should always fail");
		//    }
		//}

		[TestFixture]
		public class CreateSpecification
		{
			[Test]
			public void Should_Create_Spec_With_Correctly_Resolved_Delegate()
			{
				// Arrange

				var typeName = typeof(SatisfiesDelegateSpecTests.ValidationClass).AssemblyQualifiedName;
				var methodName = "ValidateValid";
				var expectedRuleInterpretation = "expectedRuleInterpretation";
				var fakeInfo = new FakeReflectionInfo();

				// Act
				var attribute = new SatisfiesDelegateAttribute(typeName, methodName, expectedRuleInterpretation);
				var spec = (SatisfiesDelegateSpec)attribute.CreateSpecification(fakeInfo);

				// Assert
				Assert.AreEqual(typeof(SatisfiesDelegateSpecTests.ValidationClass), spec._specDelegate.Method.DeclaringType);
				Assert.AreEqual(methodName, spec._specDelegate.Method.Name);
			}
		}
	}
}